package com.yunying.rispro.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunying.rispro.exception.BusinessException;
import com.yunying.rispro.mapper.PatientsMapper;
import com.yunying.rispro.model.Examine;
import com.yunying.rispro.mapper.ExamineMapper;
import com.yunying.rispro.model.Patients;
import com.yunying.rispro.service.IExamineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunying.rispro.util.JsonResponseBody;
import com.yunying.rispro.util.JsonResponseStatus;
import com.yunying.rispro.util.PageBean;
import com.yunying.rispro.vo.RisVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 检查信息表 服务实现类
 * </p>
 *
 * @author yunying
 * @since 2022-04-21
 */
@Service
public class ExamineServiceImpl extends ServiceImpl<ExamineMapper, Examine> implements IExamineService {

    @Autowired
    private ExamineMapper examineMapper;

    @Override
    public JsonResponseBody<List<Map<String,Object>>> queryRisPager(RisVo risVo, PageBean pageBean){
        List<Map<String, Object>> maps = examineMapper.selectRisList(risVo);
        return new JsonResponseBody<>(maps);
    }

    @Override
    public JsonResponseBody<?> addExamine(Examine examine) {
        System.out.println(examine);
         // 判断信息是否已存在
        if(examine.getExamineId()!=null && examine.getExamineId()!=0){
            int i = examineMapper.updateById(examine);
            if(i<0){
                throw new BusinessException(JsonResponseStatus.OPERATE_ERROR);
            }
        }
        examine.setExamineId(50+new Date().getTime());
        int i=examineMapper.insertExamine(examine);
        if(i<0){
            throw new BusinessException(JsonResponseStatus.OPERATE_ERROR);
        }
        return new JsonResponseBody<>();
    }

    @Override
    public Map<String, Object> queryRisById(Long examineId) {
        return examineMapper.queryRisById(examineId);
    }


}
